package com.weiaibenpao.demo.chislim.ui.activity.me;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.base.BaseActivity;
import com.weiaibenpao.demo.chislim.db.preferences.UserPreferences;
import com.weiaibenpao.demo.chislim.presenter.FeedbackPresenter;
import com.weiaibenpao.demo.chislim.view.FeedbackView;

import butterknife.BindView;
import butterknife.OnClick;

public class OpinionActivity extends BaseActivity<FeedbackView,FeedbackPresenter> implements FeedbackView {

    @BindView(R.id.opinionText)
    EditText opinionText;
    @BindView(R.id.opinionCommit)
    Button opinionCommit;
    private int userId;

    @Override
    public int setLayoutResourceID() {
        return R.layout.activity_opinion;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        userId = UserPreferences.getInstance().getInt(UserPreferences.USER_ID);
    }

    @Override
    public FeedbackPresenter initPresenter() {
        return new FeedbackPresenter();
    }

    @OnClick(R.id.opinionCommit)
    public void onClick() {
        //判断用户建议是否为空
        if (!TextUtils.isEmpty(opinionText.getText().toString().trim())) {
            //上传用户建议

        } else {
            Toast.makeText(this, this.getResources().getString(R.string.point_opinion_text), Toast.LENGTH_SHORT).show();
        }
    }


    @OnClick({R.id.left_image,R.id.opinionCommit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_image:
                finish();
                break;
            case R.id.opinionCommit:
                mPresenter.getAttentionList(userId,opinionText.getText().toString());
                break;
        }
    }

    @Override
    public void feedSuccess() {
        opinionText.setText("");
        Toast.makeText(this,this.getResources().getString(R.string.opinion_text), Toast.LENGTH_SHORT).show();
    }
}
